package com.marketlive.system.encryption;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

/*
(C) Copyright MarketLive. 2006. All rights reserved.
MarketLive is a trademark of MarketLive, Inc.
Warning: This computer program is protected by copyright law and international treaties.
Unauthorized reproduction or distribution of this program, or any portion of it, may result
in severe civil and criminal penalties, and will be prosecuted to the maximum extent
possible under the law.
*/

import org.marketlive.system.encryption.IKeyStore;

import java.util.Date;

/**
 * Implementation of the IKeyStore interface.
 */
public class KeyStore implements IKeyStore {
    private static Log log = LogFactory.getLog(KeyStore.class);

    /** The key set identifier .*/
    private String code;

    /** The private key  (used for CC NUM or Password decryption).  */
    private String privateKey;

    /** The public key  (used for CC NUM or Password encryption). */
    private String publicKey;

    /** The date the key set was created. */
    private Date dateCreated;

    /** The status of the product. */
    private boolean active;

    /** Hibernate version. */
    private int version = -1;

    public KeyStore() {
    	if (log.isDebugEnabled()) {
    		log.debug("KeyStore empty constructor called.");
    	}
    }

    public KeyStore(String code) {
        this.code = code;
    }

    /**
     * Returns the code identifier for this key store.
     * @return
     */
    public String getCode() {
        return code;
    }

    /**
     * Set the code identifier for this key store.
     * @param code
     */
    public void setCode(String code) {
        this.code = code;
    }

    /**
     * Get the private key for this key store.
     * @return  returns a byte array.
     */
    public String getPrivateKey() {
        return privateKey;
    }

    /**
     * Set the private key for this key store to the given byte array.
     * @param privateKey  a byte array.
     */
    public void setPrivateKey(String privateKey) {
        this.privateKey = privateKey;
    }

    /**
     * Returns the public key for this key store.
     * @return
     */
    public String getPublicKey() {
        return publicKey;
    }

    /**
     * Sets the public key for this key store.
     * @param publicKey  a byte array.
     */
    public void setPublicKey(String publicKey) {
        this.publicKey = publicKey;
    }

    /**
     * Returns the date this keystore was created.
     * @return
     */
    public Date getDateCreated() {
        return dateCreated;
    }

    /**
     * Set the date this keystore was created.
     * @param dateCreated
     */
    public void setDateCreated(Date dateCreated) {
        this.dateCreated = dateCreated;
    }

    /**
     * Returns the active status for this keystore.
     * @return
     */
    public boolean isActive() {
        return active;
    }

    /**
     * Set the active flag for this keystore.  Data is encrypted using the keys for the active keystore.
     * @param active
     */
    public void setActive(boolean active) {
        this.active = active;
    }

    /**
     * Used to compare in-memory version of the entity with that stored in the
     * persistence store.
     * @return version
     */
    public int getVersion() {
        return version;
    }

    /**
     * Sets the version id.  This is done by hibernate and should not be
     * modified by client code.
     * <p/>
     * @param version Hibernate version number.
     */
    public void setVersion(final int version) {
        this.version = version;
    }
}
